package br.ufal.tci.nexos.arcolive.util;

import br.ufal.tci.nexos.arcolive.exception.ArCoLIVEException;
import br.ufal.tci.nexos.arcolive.persistence.GenericResultSet;
import br.ufal.tci.nexos.arcolive.service.connection.ConnectionRequest;

public class CommandValidator {
	
	public static boolean validate(ConnectionRequest request, GenericResultSet parametersCommand) {
		String parameter;
		String type;
		while (parametersCommand.next()) {
			parameter = parametersCommand.getValue("name");
			type      = parametersCommand.getValue("type");
			try {
				
				if (type.equalsIgnoreCase("java.lang.Integer")) {
					request.getSafelyIntegerParameter(parameter);
				} else
	
				if (type.equalsIgnoreCase("java.lang.String")) {
					request.getSafelyStringParameter(parameter);
				} else 
					
				if (type.equalsIgnoreCase("java.lang.Long")) {
					request.getSafelyLongParameter(parameter);
				}
				
			} catch (ArCoLIVEException e) {
				return false;
			}
		}
		return true;
	}
	
}
